package meijuli.com.join51.business.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import meijuli.com.join51.business.R;

/**
 *
 *
 * @author wenqin 2017-05-12 10:12
 */

public class BaseFragmentActivity extends BaseActivity {
    TextView mToolbarTitle;
    TextView mTextMenu;
    Toolbar mToolbar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();

    }

    private void init() {
        setContentView(R.layout.activity_base_fragment);
        mToolbarTitle = findViewById(R.id.toolbar_title);
        mTextMenu = findViewById(R.id.text_menu);
        mToolbar = findViewById(R.id.toolbar);
        initToolBar();
    }

    public void setToolBarTitle(String s) {
        mToolbarTitle.setText(s);
    }

    protected void setRightText(String s) {
        setRightText(s, null);
    }

    protected void setRightText(String s, View.OnClickListener listener) {
        mTextMenu.setText(s);
        mTextMenu.setVisibility(View.VISIBLE);
        mTextMenu.setOnClickListener(listener);
    }

    private void initToolBar() {
        mToolbar.setTitle("");
        mToolbar.setNavigationIcon(R.mipmap.icon_back_white);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!getSupportFragmentManager().popBackStackImmediate()) {
                    finish();
                }
            }
        });
    }
}
